package cn.orangeframe.neon.application.mapper;

import cn.orangeframe.neon.application.exception.TerminateWorkflowException;
import cn.orangeframe.neon.application.util.ParametersUtils;
import cn.orangeframe.neon.domain.enums.TaskStatus;
import cn.orangeframe.neon.domain.enums.TaskType;
import cn.orangeframe.neon.domain.model.TaskModel;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Component(TaskType.TASK_TYPE_HTTP)
public class HttpTaskMapper implements TaskMapper {

    private final ParametersUtils parametersUtils;

    public HttpTaskMapper(ParametersUtils parametersUtils) {
        this.parametersUtils = parametersUtils;
    }

    @Override
    public String getTaskType() {
        return TaskType.TASK_TYPE_HTTP;
    }

    @Override
    public List<TaskModel> getMappedTasks(TaskMapperContext taskMapperContext) throws TerminateWorkflowException {

        Map<String, Object> taskInput = taskMapperContext.getTaskInput();
        int retryCount = taskMapperContext.getRetryCount();

        TaskModel httpTask = taskMapperContext.createTaskModel();
        httpTask.setInputData(taskInput);
        httpTask.setRetryCount(retryCount);
        httpTask.setStatus(TaskStatus.SCHEDULED);
        return List.of(httpTask);
    }
}
